<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>	
  <script type="text/javascript" src="/js/jquery-md5-min.js"></script>
  
  <title>WHQ | 基础平台</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <script>
  var add_url = "${ctx}/res/uct/admin/saveUser";
  var del_url = "${ctx}/res/uct/admin/delUser";
  var view_url = "${ctx}/trans/info/userInfo";
  //var org_url = "${ctx}/uct/org/org!initOrg.action";
  var org_url = "${ctx}/trans/list/orgInit";
  var dept_url = "${ctx}/trans/list/deptInit";//?orgId=${item.orgId}
  var id;
  </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="">

  <div class="">
		<ol class="breadcrumb bgblue">
			<li><span class="label label-danger font14" >机构与用户管理 /用户管理</span></li>
		</ol>
    <!-- Main start -->

<section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header">
              	<center>
              		<div class="btn-group">
						<button class="btn btn-info" type="button" onclick="toAdd();">增加</button>
				        <button class="btn btn-info" type="button" onclick="del();">删除</button>
				        <button class="btn btn-info" type="button" onclick="toEdit();">修改</button>
				        <button class="btn btn-info" type="button" onclick="refresh();">刷新</button>
				        <button class="btn btn-info" type="button" onclick="toAct();">用户权限</button>
			        </div>					
            	</center>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            <center>
				<form id="searchFrom" class="form-horizontal">
				<input type="hidden" name="userStatus" value="1"/>
				<input type="hidden" name="doCode" value="userList"/>
				<c:if test="${loginUser.sysFlag !='1'}">
				   <input type="hidden" name="orgId" value="${loginUser.dataOrgIds }${loginUser.orgId }"/>
				</c:if>
				用户账号：<input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="userEname" id="userEname" value="" />
				用户姓名: <input type="text" class="form-control" style="height: 30px; display: inline; width: 13%;"  name="userCname" id="userCname" value="" />
				<button type="button" class="btn btn-primary" onclick="getTableData();">查询</button>
				<button  type="button" class="btn btn-primary" onclick="cleanData('searchFrom');">重置 </button>
				</form>
				</center>
              <table id="example" class="table table-bordered table-hover" >
                <thead>
                <tr>
                  <th>用户账号</th><th>用户姓名</th>
                  <th>所属机构</th><th>所属部门</th>
                  <th>上级领导</th><th>用户类型</th>
                  <th>性别</th><th>手机</th><th>状态</th>
                </tr>
                </thead><tbody id="myList"></tbody>
              </table>
         	    <center><ul id="pageList"></ul></center>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- Main end -->
  </div>
  
<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
				<div class="modal-content" id="user-editManager"></div>
				<!-- /.modal-content -->
			</div>		
</div>  
  
<div class="modal fade" id="act_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:900px;">
				<div class="modal-content" id="user-acts"></div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>    
  
</body>
	<script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr>
					<td style="display:none;"><?=rows[i].userId?></td>
					<td><?=rows[i].userEname?></td>
					<td><?=rows[i].userCname?></td>
					<td><?=rows[i].orgEname?></td>
					<td><?=rows[i].deptName?></td>
					<td><?=rows[i].fax?></td>
					<td><?=rows[i].userType?></td>
					<td><?=rows[i].userSex?></td>
					<td><?=rows[i].mobile?></td>
					<td><?=rows[i].userStatus?></td>
				</tr>
     		<?}?>
	</script>

<script>
var clickMenu= 'user-list';
$(function () {
	getTableData();
	$("#user-editManager").load("${ctx}/template/uct/user-edit.html",function(){loadItems(code,cname);});
	$('#example tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	            //$(this).removeClass('selected');
	        } else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     id = $('tr.selected td').eq(0).html();
	   //  console.log($('tr.selected td').eq(1).html())
	   
	} );
	DictUtil.getDictExtList("#userType", dictUrl, {cateEname:"userType"});//用户类型
	DictUtil.getRadioList("#userSexDiv","userSex", dictUrl,{cateEname:"userSex"});//用户性别 
  });
//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'hide.bs.modal' ,function(e){  
	cleanData('userFormData');
}); 

//设置模态框隐藏事件钩子  
$( '#my_modal' ).on( 'show.bs.modal' ,function(e){  
	$.ajax({ type:'get',url:'${ctx}/sendPage/token?token=true',
	    dataType:'json', success: function(myData){
			 $('#formToken').val(myData);
	  	}
	});	

	initOrg("orgId");
}); 

function cleanData(id){
	$(':input','#'+id)  
	 .not(':button, :submit, :reset, :hidden')  
	 .val('')  
	 .removeAttr('selected'); 
}

function getTableData(){
	deleteAllRow('example');
	$("#act-userId").val(id);
	$.ajax({
		   type:'get',
		   url:common_list_url,//user_search_url,
		   data:$('#searchFrom').serialize()+getCurrentPage(common_list_url+"?"+$('#searchFrom').serialize(),10),
		   dataType:'json',
		   success: function(myData){
			var data = baidu.template('dataList',eval(myData));  
			$("#myList").html(data);
			  var option= {
					   ele:$("#pageList")[0],
					   total:myData.total,
					   fn:getTableData,
					   url:common_list_url+"?"+$('#searchFrom').serialize()
				   }
			generatePages(option);
		   }
		});	
  }
  
function getRoleListData(){
	deleteAllRow('roleList');
	$("#act-userId").val(id);
	$.ajax({ type:'post', url:'${ctx}/res/uct/admin/userRoleData?userId='+id,
		   data:$('#actFrom').serialize(), dataType:'json',
		   success: function(myData){
			var data = baidu.template('roleListData',eval(myData));  
			$("#roleList").html(data);
		   }
	 });	
  } 

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=1;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}
function toAdd(){
	$("#if-sysFlag").show();
	$('#my_modal').modal('show');
}

function getObjInfo(myData){
	 FormUtil.loadView("", myData);
	 $('#my_modal').modal('show');
}
function toAct(){
	$('#table1 tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        } else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	} );
	//getRoleListData();
	$("#user-acts").load("${ctx}/template/uct/user-acts.html",function(){getRoleListData();});
	$('#act_modal').modal('show');
}

function cannel(modalId){
	$('#'+modalId).modal('hide');
}

function initOrg(selectId){
	$("#"+selectId).html("");
	$("#"+selectId).append("<option value=''>--请选择--</option>");
	$.ajax({url: org_url,  async:false,
        type: "get",dataType: "text",
        success: function(data){
        	var obj = $.parseJSON(data);
			for(var i = 0; i < obj.length; i++){
				$("#"+selectId).append("<option value='"+obj[i].orgId+"'>"+obj[i].orgCname+"</option>");
			}
        }
    });
}

//value:orgId
function initDept(selectId,value){
	//alert(selectId+"|"+value);
	$("#"+selectId).html("");
	$("#"+selectId).append("<option value=''>--请选择--</option>");
	$.ajax({ url: dept_url, data:{'orgId':value},
        async:false,type: "get", dataType: "text",
        success: function(data){
        	var obj = $.parseJSON(data);
			for(var i = 0; i < obj.length; i++){
				$("#"+selectId).append("<option value='"+obj[i].deptId+"'>"+obj[i].deptCname+"</option>");
			}
        }
    });
}

function refresh(){
	getTableData();
}

</script>

</html>
